﻿using System;
using System.Security.Cryptography;

namespace FrameWork
{
    partial class RsaFromPkcs8
    {
        public static RSAParameters ConvertFromPublicKey(string pemFileConent)
        {

            var keyData = Convert.FromBase64String(pemFileConent);
            if (keyData.Length < 162)
            {
                throw new ArgumentException("pem file content is incorrect.");
            }
            var pemModulus = new byte[128];
            var pemPublicExponent = new byte[3];
            Array.Copy(keyData, 29, pemModulus, 0, 128);
            Array.Copy(keyData, 159, pemPublicExponent, 0, 3);
            var para = new RSAParameters();
            para.Modulus = pemModulus;
            para.Exponent = pemPublicExponent;
            return para;
        }
    }
}
